package com.xyh.bean;

import com.xyh.utils.PropertiesUtils;

import java.util.Collections;
import java.util.Set;

public class Constants {

    public static String PROJECT_NAME;

    public static String PROJECT_DESCRIPTION;
    public static String PROJECT_GROUP_ID;
    public static String PROJECT_VERSION;
    public static String DB_DRIVER_NAME;
    public static String SERVER_PORT;


    public static String REDIS_HOST;
    public static String REDIS_PORT;
    public static String REDIS_DB;
    public static String REDIS_PASSWORD;

    // 数据库连接URL
    public static String DB_URL;
    // 数据库用户名
    public static String DB_USERNAME;
    // 数据库密码
    public static String DB_PASSWORD;


    public static  String SUFFIX_CONTROLLER ;
    public static  String PACKAGE_BASE;

    public static  String PACKAGE_PARAM;
    public static  String PACKAGE_PO;
    public static  String PACKAGE_MAPPER;
    public static  String PACKAGE_MAPPER_XML;
    public static  String PACKAGE_SERVICE;
    public static  String PACKAGE_SERVICE_IMPL;
    public static  String PACKAGE_UTILS;
    public static  String PACKAGE_ENUMS;
    public static  String PACKAGE_VO;
    public static  String PACKAGE_CONFIG;
    public static  String PACKAGE_EXCEPTION;
    public static  String PACKAGE_CONTROLLER;




    public static String  AUTHOR;

    public static  String PATH_BASE;
    public static  String PATH_PO;
    public static  String PATH_UTILS;
    public static  String PATH_JAVA ;
    public static  String PATH_RESOURCES = "resources";
    public static  String PATH_ENUMS;
    public static  String PATH_PARAM;
    public static  String PATH_MAPPER;
    public static  String PATH_MAPPER_XML;
    public static  String PATH_SERVICE;
    public static  String PATH_SERVICE_IMPL;
    public static  String PATH_VO;
    public static  String PATH_CONFIG;
    public static  String PATH_EXCEPTION;
    public static  String PATH_CONTROLLER;
    public static  String PATH_ROOT;




    // 是否忽略表前缀的配置项
    public static final Boolean IGNORE_TABLE_PREFIX;
    // Bean参数的后缀配置项
    public static String SUFFIX_BEAN_PARAM;
    public static String SUFFIX_BEAN_PARAM_FUZZY;
    //suffix.bean.param.time.start
    public static String SUFFIX_BEAN_PARAM_TIME_START;
    public static String SUFFIX_BEAN_PARAM_TIME_END;
    public static String SUFFIX_MAPPER;
    public static  String SUFFIX_SERVICE;


    // 忽略的Bean参数的配置项
    public static String IGNORE_BEAN_TO_JSON_FIELD;
    public static String IGNORE_BEAN_TO_JSON_EXPRESS;
    public static String IGNORE_BEAN_TO_JSON_EXPRESS_CLASS;
    public static String IGNORE_TABLE_SUFFIX;
    // 日期序列化
    public static String DATE_FORMAT_EXPRESS;
    public static String DATE_FORMAT_CLASS;
    //日期反序列化
    public static String DATE_FORMAT_DESERIALIZE;
    public static String DATE_FORMAT_DESERIALIZE_CLASS;


    // 静态代码块用于初始化配置项常量
    static {
        PROJECT_NAME = PropertiesUtils.getProperty("project.name");

        DB_DRIVER_NAME = PropertiesUtils.getProperty("db.driver.name");
        DB_URL = PropertiesUtils.getProperty("db.url");
        DB_USERNAME = PropertiesUtils.getProperty("db.username");
        DB_PASSWORD = PropertiesUtils.getProperty("db.password");
        SERVER_PORT= PropertiesUtils.getProperty("server.port");

        REDIS_HOST= PropertiesUtils.getProperty("redis.host");
        REDIS_PORT= PropertiesUtils.getProperty("redis.port");
        REDIS_DB= PropertiesUtils.getProperty("redis.db");
        REDIS_PASSWORD= PropertiesUtils.getProperty("redis.password");

        PROJECT_DESCRIPTION = PropertiesUtils.getProperty("project.description");
        PROJECT_GROUP_ID = PropertiesUtils.getProperty("project.groupId");
        PROJECT_VERSION = PropertiesUtils.getProperty("project.version");
        AUTHOR = PropertiesUtils.getProperty("author");
        // 基础路径配置
        PATH_BASE = PropertiesUtils.getProperty("path.base");
        // 处理路径末尾斜杠
        PATH_BASE = PATH_BASE.replaceAll("/+$", "") + "/";
        PATH_ROOT = PATH_BASE;
        PATH_JAVA = PATH_BASE + "java" + "/";
        PATH_ROOT = PATH_ROOT.replace("src/main/", "");
        PATH_RESOURCES = PATH_BASE + PATH_RESOURCES;
        PATH_BASE = PATH_BASE                   // 原始路径
                + "java"                     // 追加Java目录
                + "/" + PropertiesUtils.getProperty("package.base"); // 追加基础包名
        PATH_BASE = PATH_BASE.replace(".", "/"); // 将包结构转换为目录结构

        // PO实体类路径配置
        PATH_PO = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.po").replace(".", "/");


        // 包名层级配置
        final String packageBase = PropertiesUtils.getProperty("package.base"); // 基础包名

        PACKAGE_BASE = packageBase;
        // 从属性文件中读取是否忽略表前缀的配置，并转换为Boolean类型
        IGNORE_TABLE_PREFIX = Boolean.valueOf(PropertiesUtils.getProperty("ignore.table.prefix"));
        // 从属性文件中读取Bean参数的后缀配置
        SUFFIX_BEAN_PARAM = PropertiesUtils.getProperty("suffix.bean.param");
        SUFFIX_BEAN_PARAM_FUZZY = PropertiesUtils.getProperty("suffix.bean.param.fuzzy");
        SUFFIX_BEAN_PARAM_TIME_START = PropertiesUtils.getProperty("suffix.bean.param.time.start");
        SUFFIX_BEAN_PARAM_TIME_END = PropertiesUtils.getProperty("suffix.bean.param.time.end");
        SUFFIX_MAPPER = PropertiesUtils.getProperty("suffix.mapper");
        SUFFIX_SERVICE = PropertiesUtils.getProperty("suffix.service");
        SUFFIX_CONTROLLER = PropertiesUtils.getProperty("suffix.controller");
        PACKAGE_PARAM =packageBase + "." +  PropertiesUtils.getProperty("package.param");
        PATH_PARAM = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.param").replace(".", "/");

        // 忽略的Bean参数的配置项
        IGNORE_BEAN_TO_JSON_FIELD = PropertiesUtils.getProperty("ignore.bean.toJson.field");
        IGNORE_TABLE_SUFFIX = PropertiesUtils.getProperty("ignore.table.suffix");
        IGNORE_BEAN_TO_JSON_EXPRESS = PropertiesUtils.getProperty("ignore.bean.toJson.field.express");
        IGNORE_BEAN_TO_JSON_EXPRESS_CLASS = PropertiesUtils.getProperty("ignore.bean.toJson.field.express.class");
        // 日期序列化
        DATE_FORMAT_EXPRESS = PropertiesUtils.getProperty("date.format.express");
        DATE_FORMAT_CLASS = PropertiesUtils.getProperty("date.format.class");
        //日期反序列化
        DATE_FORMAT_DESERIALIZE = PropertiesUtils.getProperty("date.format.deserialize");
        DATE_FORMAT_DESERIALIZE_CLASS = PropertiesUtils.getProperty("date.format.deserialize.class");




        PACKAGE_PO = packageBase + "." + PropertiesUtils.getProperty("package.po");  // 实体类包

        // 分层架构包名配置
        PACKAGE_MAPPER = packageBase + "." + PropertiesUtils.getProperty("package.mapper");       // Mapper层
        PATH_MAPPER= PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.mapper").replace(".", "/");
        PACKAGE_UTILS = packageBase + "." + PropertiesUtils.getProperty("package.utils");
        PATH_UTILS = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.utils").replace(".", "/");

        PACKAGE_ENUMS = packageBase + "." + PropertiesUtils.getProperty("package.enums");
        PATH_ENUMS = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.enums").replace(".", "/");
        PATH_MAPPER_XML = PATH_RESOURCES
                + "/" + PropertiesUtils.getProperty("package.mapper.xml").replace(".", "/");
        PACKAGE_SERVICE = packageBase + "." + PropertiesUtils.getProperty("package.service");      // Service接口
        PACKAGE_SERVICE_IMPL = packageBase + "." + PropertiesUtils.getProperty("package.service.impl"); // Service实现
        PATH_SERVICE = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.service").replace(".", "/");
        PATH_SERVICE_IMPL = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.service.impl").replace(".", "/");
        PACKAGE_VO = packageBase + "." + PropertiesUtils.getProperty("package.vo");
        PATH_VO = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.vo").replace(".", "/");
        PACKAGE_CONFIG = packageBase + "." + PropertiesUtils.getProperty("package.config");
        PATH_CONFIG = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.config").replace(".", "/");
        PACKAGE_EXCEPTION = packageBase + "." + PropertiesUtils.getProperty("package.exception");
        PATH_EXCEPTION = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.exception").replace(".", "/");
        PACKAGE_CONTROLLER = packageBase + "." + PropertiesUtils.getProperty("package.controller");
        PATH_CONTROLLER = PATH_BASE
                + "/" + PropertiesUtils.getProperty("package.controller").replace(".", "/");

    }

    public static void main(String[] args) {

        System.out.println(PATH_JAVA);
    }

    // SQL日期时间类型（补充时区相关类型）
    public static final Set<String> SQL_DATE_TIMES_TYPES = Collections.unmodifiableSet(
            Set.of("datetime", "timestamp", "datetime2", "datetimeoffset") //
    );

    // SQL日期类型（补充时间间隔类型）
    public static final Set<String> SQL_DATE_TYPES = Collections.unmodifiableSet(
            Set.of("date", "year", "interval") //
    );

    // SQL小数类型（补充货币类型）
    public static final Set<String> SQL_DECIMAL_TYPES = Collections.unmodifiableSet(
            Set.of("decimal", "numeric", "float", "double", "real", "money", "smallmoney") //
    );

    // SQL整数类型（补充无符号标识）
    public static final Set<String> SQL_INT_TYPES = Collections.unmodifiableSet(
            Set.of("tinyint", "smallint", "mediumint", "int", "integer", "tinyint unsigned", "smallint unsigned") //
    );

    // SQL长整数类型（补充序列类型）
    public static final Set<String> SQL_LONG_TYPES = Collections.unmodifiableSet(
            Set.of("bigint","bigint unsigned", "serial") //
    );

    // SQL字符串类型（补充Unicode和枚举类型）
    public static final Set<String> SQL_STRING_TYPES = Collections.unmodifiableSet(
            Set.of("char", "varchar", "tinytext", "text", "mediumtext", "longtext",
                    "nchar", "nvarchar", "ntext", "enum", "set") //
    );

    // SQL二进制类型（补充变长二进制）
    public static final Set<String> SQL_BLOB_TYPES = Collections.unmodifiableSet(
            Set.of("blob", "tinyblob", "mediumblob", "longblob", "binary", "varbinary", "image") //
    );


}